/* 
 * Advanced Foundation Classes
 * Copyright (C) 2000/2004  Fabio Rotondo - Andrea Galimberti
 *  
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *  
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *  
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
#include "../easygui.h"
#include "../widgets.h"

int key_clicked ( DynamicClass * dc, EasyGUIContext * context, int key_val, short clicked )
{
	printf ( "Key: %d - Clicked: %d\n", key_val, clicked );
	return ( 0 );
}

int win_focus ( DynamicClass * dc, EasyGUIContext * context )
{
	printf ( "Win Activated\n" );

	return ( 0 );
}

int opt_menu_changed ( DynamicClass * dc, EasyGUIContext * context, int selected )
{
	printf ( "Option Menu, selected: %d\n", selected );
	return ( 0 );
}

int dummy ( DynamicClass * dc, EasyGUIContext * context )
{
	fprintf ( stdout, "Hello world!\n" );

	afc_easygui_widget_execute ( context, "PIPPO", "add", "Col1", "Col2", "Col3", "info!", AFC_EASYGUI_ARG_END );

	//afc_easygui_widget_set_attrs ( data, "clist", "nome_lista", AFC_EASYGUI_ARG_NODEMASTER, albero, AFC_TAG_END );

	return ( 0 );
}

int set_titles ( DynamicClass * dc, EasyGUIContext * context )
{
	afc_easygui_widget_execute ( context, "PIPPO", "set_titles", "Title1", "Tit.2", "Titol-3", AFC_EASYGUI_ARG_END );

	return ( 0 );
}

int toggle ( DynamicClass * dc, EasyGUI * egui )
{
	afc_dynamic_class_execute ( dc, "get_value", AFC_DYNAMIC_CLASS_ARG_END );

	fprintf ( stderr, "Toggled!: %d\n", ( int ) dc->result );

	return ( 0 );
}

int combo ( DynamicClass * dc, EasyGUI * egui, const char * text )
{
	fprintf ( stderr, "Combo activated! Value: %s\n", text );

	return ( 0 );
}

int entry_activate ( DynamicClass * dc, EasyGUI * egui, const char * text )
{
	fprintf ( stderr, "Entry Activated: %s\n", text );

	return ( 0 );
}

short entry_inserted ( DynamicClass * dc, EasyGUI * egui, char * str, int len )
{
	fprintf ( stderr, "Entry Inserted: %s (%d)\n", str, len );

	afc_string_upper ( str );

	return ( TRUE );
}

int radio_toggled ( DynamicClass * dc, EasyGUI * egui, short active )
{
	fprintf ( stderr, "Radio Button Toggled! Active: %d\n", active );

	return ( 0 );
}

int clist_act ( DynamicClass * dc, EasyGUIContext * context, void * info )
{
	fprintf ( stderr, "ROW double click info: %s\n", ( char * ) info );

	return ( 0 );
}

short clist_sel ( DynamicClass * dc, EasyGUIContext * context, short sel, void * info )
{
	fprintf ( stderr, "Col: %s - Previous: %d\n", ( char * ) info, sel );

	return ( TRUE );
}

int clist_col ( DynamicClass * dc, EasyGUIContext * context, int col, void * info )
{
	fprintf ( stderr, "Col Clicked: %d\n", col );
	
	return ( TRUE );
}

int btn_new_window ( DynamicClass * dc, EasyGUI * egui )
{
	EasyGUIContext * c;

	c = afc_easygui_add_context ( egui, NULL );

	afc_easygui_context_set_gui_from_file ( c, "gui_descr.txt" );

	afc_easygui_context_show ( c );

	return ( AFC_ERR_NO_ERROR );
}

int main ( int argc, char * argv[] )
{
	AFC * afc = afc_new (); 
	EasyGUI * easygui;
	EasyGUIContext * context;
	int afc_res = 0;

	afc_track_mallocs ( afc );
	afc_set_tags ( afc, AFC_TAG_LOG_LEVEL, 	AFC_LOG_WARNING, 
			    AFC_TAG_SHOW_FREES, FALSE,
			    AFC_TAG_SHOW_MALLOCS, FALSE,
			    AFC_TAG_END );

	easygui = afc_easygui_new ( afc );

	if ( easygui == NULL ) 
	{
	  fprintf ( stderr, "Init of class EasyGUI failed.\n" );
	  return ( 1 );
	}

	if ( argc < 2 )
	{
		fprintf ( stderr, "Invalid args: %d\n", argc );
		return ( 1 );
	}

	afc_easygui_init ( easygui );
	context = afc_easygui_add_context ( easygui, AFC_EASYGUI_CONTEXT_MAIN );

	afc_easygui_context_set_gui_from_file ( context, argv[1]);

	//afc->debug_level = AFC_DEBUG_EVERYTHING; 

	if ( ( afc_res = afc_easygui_context_show ( context ) ) != AFC_ERR_NO_ERROR ) {
		fprintf ( stderr, "res: %x\n", afc_res );
	}
	else afc_easygui_main ( easygui );

	afc_easygui_delete ( easygui );

	afc_delete ( afc );

	return ( 0 ); 
}
